#pragma once
#ifndef __G_TIME_MANAGER_H__
#define __G_TIME_MANAGER_H__

#include <list>

#include "../../Foundation/GUtilities/GTypes.h"
#include "../../Foundation/GUtilities/GTimer.h"
#include "../../Foundation/GUtilities/GSingleton.h"
#include "../../Foundation/GUtilities/GInitializable.h"

#include "../../Foundation/GThread/GCriticalSection.h"

namespace GEngine
{
	// Class for managing timed callbacks and engine timings
	class GTimeManager : public GUtil::GInitializable, public GUtil::GSingleton<GTimeManager>
	{
	friend class GCore;
	friend class GUtil::GSingleton<GTimeManager>;

	typedef std::list<GUtil::GTimer*> TimerList;

	private:
		double			UpdateTime;
		GUtil::GTimer	UpdateTimer;
		
		double			FrameTime;
		GUtil::GTimer	FrameTimer;

		GUtil::GTimer	UpTimer;

		TimerList		Timers;
		
						GTimeManager();
						~GTimeManager();

		void			AdvanceFrameTime();
		void			AdvanceUpdateTime();
		
	public:
		GUInt64			GetUpTime() const;

		double			GetUpdateTime() const;
		double			GetFrameTime() const;

		void			ResetTimers();
		void			ClearTimers();

		void			AppendTimer(GUtil::GTimer* Timer);
		void			RemoveTimer(GUtil::GTimer* Timer);

		void			Update();

		bool			Initialize() OVERRIDE;
		void			Uninitialize() OVERRIDE;
	
	};

}

#define mGTimeManager	GEngine::GTimeManager::GetInstance()

#endif